/**
 * 
 */
package kr.co.insoft.driver.model;

import java.util.ArrayList;
import java.util.List;

import kr.co.insoft.driver.DriverFactory;

/**
 * 제공할 cloud target
 * 
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@SuppressWarnings("rawtypes")
public enum CloudSponsor {
	AMAZON {
		@Override
		public Boolean isPossible() {
			try {
				Class clz = Class.forName(DriverFactory.AMAZON_PACKAGE_CLASS);
				if (clz != null)
					return true;
			} catch (Exception e) {
				return false;
			}
			return false;
		}

		@Override
		public String getDescription() {
			return "Amazon Cloud Service"; // writing these type description.
		}

		@Override
		public String getCloudName() {
			return "AWS"; // writing these type description.
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see kr.co.insoft.driver.model.CloudSponsor#getProvider()
		 */
		@Override
		public String getProvider() {
			return "aws-ec2";
		}
	},
	RACKSPACE_US {
		@Override
		public String getCloudName() {
			return "RackSpace US Cloud Service";
		}

		@Override
		public String getDescription() {
			return "RackSpace US Cloud Service";
		}

		@Override
		public Boolean isPossible() {
			try {
				Class clz = Class
						.forName(DriverFactory.RACKSPACE_UK_PACKAGE_CLASS);
				if (clz != null)
					return true;
			} catch (Exception e) {
				return false;
			}
			return false;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see kr.co.insoft.driver.model.CloudSponsor#getProvider()
		 */
		@Override
		public String getProvider() {
			return "rackspace-cloudservers-us";
		}
	},
	RACKSPACE_UK {
		@Override
		public String getCloudName() {
			return "RackSpace UK Cloud Service";
		}

		@Override
		public String getDescription() {
			return "RackSpace UK Cloud Service";
		}

		@Override
		public Boolean isPossible() {
			try {
				Class clz = Class
						.forName(DriverFactory.RACKSPACE_US_PACKAGE_CLASS);
				if (clz != null)
					return true;
			} catch (Exception e) {
				return false;
			}
			return false;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see kr.co.insoft.driver.model.CloudSponsor#getProvider()
		 */
		@Override
		public String getProvider() {
			return "rackspace-cloudservers-uk";
		}
	},
	OPENSTACK {
		@Override
		public String getCloudName() {
			return "OpenStack Cloud Service";
		}

		@Override
		public String getDescription() {
			return "OpenStack Cloud Service";
		}

		@Override
		public Boolean isPossible() {
			try {
				Class clz = Class
						.forName(DriverFactory.OPENSTACK_PACKAGE_CLASS);
				if (clz != null)
					return true;
			} catch (Exception e) {
				return false;
			}
			return false;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see kr.co.insoft.driver.model.CloudSponsor#getProvider()
		 */
		@Override
		public String getProvider() {
			return "openstack-nova";
		}
	};

	public abstract Boolean isPossible();

	public abstract String getDescription();

	public abstract String getCloudName();

	public abstract String getProvider();

	/**
	 * 사용 가능한 Driver 목록을 반환한다.
	 * 
	 * @return
	 */
	public static List<CloudSponsor> getPossibleSponsor() {
		List<CloudSponsor> result = new ArrayList<CloudSponsor>();
		for (CloudSponsor cloud : CloudSponsor.values()) {
			if (cloud.isPossible())
				result.add(cloud);
		}
		return result;
	}
}
